package com.itheima.BufferedStream.ReaderSortWrite;

import java.io.*;
import java.util.Arrays;
import java.util.Map;

public class BufferedSortWriteDemo2 {
    public static void main(String[] args) throws IOException {
        //读取本地数据
        //创建字符缓冲输入流
        BufferedReader bf1 = new BufferedReader(new FileReader("day623-24CharStream\\sort.txt"));

        //读取
        String line = bf1.readLine();
        System.out.println("读取的数据为：" + line);
        bf1.close();

        String[] Msg = line.split(" ");

        Arrays.sort(Msg, (o1, o2) -> Integer.parseInt(o1) - Integer.parseInt(o2));
        System.out.println("排序后" + Arrays.toString(Msg));

        bf1.close();

        //把排序之后结果写回到本地
        //创建输出流，将上面排序好的数据再写回本地文件
        BufferedWriter bw1 = new BufferedWriter(new FileWriter("day623-24CharStream\\sort.txt",true));
        //先写一格换行
        bw1.newLine();
        //写出
        bw1.write(Arrays.toString(Msg));
        //释放资源
        bw1.close();

    }


}

